package com.itcat.service.impl;

import com.itcat.api.mysql.UmsAdminApi;
import com.itcat.api.mysql.UmsAdminLoginLogApi;
import com.itcat.mysql.pojo.UmsAdmin;
import com.itcat.mysql.pojo.UmsAdminLoginLog;
import com.itcat.service.TimeLineService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * [一句话描述该类的功能]
 *
 * @author : [Cr Mr]
 * @version : [v1.0]
 * @date : [2022/4/2 21:59]
 */
@Service
public class TimeLineServiceImpl implements TimeLineService {
    @DubboReference
    private UmsAdminApi umsAdminApi;

    /***
     * 异步方法(存储本次登录时间)
     * @author Cr Mr
     * @date 2022/4/2 21:46
     */
    @Override
    @Async
    public void saveLoginTime(Long id) {
        umsAdminApi.saveLoginTime(id);
    }


    @DubboReference
    private UmsAdminLoginLogApi loginLogApi;

    /***
     * 添加登录记录
     * @author Cr Mr
     * @date 2022/4/2 22:07
     */
    @Override
    @Async
    public void insertLoginLog(UmsAdmin admin, String remoteAddr) {
        if (admin == null) {
            return;
        }
        UmsAdminLoginLog loginLog = new UmsAdminLoginLog();
        loginLog.setAdminId(admin.getId());
        loginLog.setIp(remoteAddr);
        loginLogApi.add(loginLog);
    }
}
